package topofstack.networkserverutils.adapter;

import java.util.ArrayList;
import java.util.List;

import topofstack.networkserverutils.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EmailServerAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater mLayoutInflater;
	private List<String> servers;
	
	public EmailServerAdapter(Context context) {
		this.context = context;
		mLayoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		servers = new ArrayList<String>();
	}
	
	public int getCount() {
		return servers.size();
	}

	public Object getItem(int position) {
		return servers.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		
		View view = convertView;
		if(view == null)
			view = mLayoutInflater.inflate(R.layout.server, null);
		
		TextView name = (TextView) view.findViewById(R.id.server_name);
		name.setText(servers.get(position));
		
		return view;
	}
	
	public void update(List<String> servers) {
		this.servers = servers;
		notifyDataSetChanged();
	}
}
